package com;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.UserDaoImp;
import com.vo.Users;

public class UserModify extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		int id=0;
		try {
			id = Integer.parseInt(request.getParameter("ID"));
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		String uname = request.getParameter("name");
		String passw = request.getParameter("passWord");
		String sex = request.getParameter("sex");
		//sex= new String(sex.getBytes("iso8859-1"),"utf-8");
		int y = Integer.parseInt(request.getParameter("birthyear"));
		int m = Integer.parseInt(request.getParameter("birthmonth"));
		int d = Integer.parseInt(request.getParameter("birthday"));
		String birth = y+"-"+m+"-"+d;
		String moble = request.getParameter("mobile");
		String address = request.getParameter("address");
		UserDaoImp daoImp = new UserDaoImp();
		Users users = new Users();
		users.setEu_user_name(uname);
		users.setEu_password(passw);
		users.setEu_sex(sex);
		users.setEu_birthday(birth);
		users.setEu_mobile(moble);
		users.setEu_address(address);
		users.setEu_user_id(id);
		System.out.println("test:"+id +users.getEu_address()+users.getEu_birthday()+users.getEu_password());
		int a = 0;
		try {
			a = daoImp.updateUser(users);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(a > 0){
			response.sendRedirect("userServlet");
		}else{
			response.sendRedirect("manage/err.jsp");
		}
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
